Public Class AddNotesForShoppingCart
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents lblMessage As System.Web.UI.WebControls.Label
    Protected WithEvents btnSave As System.Web.UI.WebControls.Button
    Protected WithEvents ValidationSummary1 As System.Web.UI.WebControls.ValidationSummary
    Protected WithEvents txtNotes As System.Web.UI.WebControls.TextBox
    Protected WithEvents hidChanged As System.Web.UI.HtmlControls.HtmlInputHidden

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Property ItemNo() As Integer
        Get
            If (viewstate("ItemNo") Is Nothing) Then
                Return 0
            Else
                Return Convert.ToInt16(viewstate("ItemNo"))
            End If

        End Get
        Set(ByVal Value As Integer)
            viewstate("ItemNo") = Value
        End Set
    End Property

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If (Not Me.IsPostBack) Then
            If (Not Request.QueryString("index") Is Nothing AndAlso Request.QueryString("index").Length > 0) Then
                ItemNo = Convert.ToInt16(Request.QueryString("index"))
            End If

            'Load data
            Dim oCollection As New Collection
            If (Not Session(Constant.SS_SHOPPING_LIST) Is Nothing) Then
                oCollection = DirectCast(Session(Constant.SS_SHOPPING_LIST), Collection)
            End If
            For i As Integer = 1 To oCollection.Count
                If (DirectCast(oCollection(i), ShoppingItem).ItemNo = ItemNo) Then
                    txtNotes.Text = DirectCast(oCollection(i), ShoppingItem).Notes
                    Exit For
                End If
            Next
        End If
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim oCollection As New Collection

        If (Not Session(Constant.SS_SHOPPING_LIST) Is Nothing) Then
            oCollection = DirectCast(Session(Constant.SS_SHOPPING_LIST), Collection)
        End If

        For i As Integer = 1 To oCollection.Count
            If (DirectCast(oCollection(i), ShoppingItem).ItemNo = ItemNo) Then
                DirectCast(oCollection(i), ShoppingItem).Notes = txtNotes.Text
                Exit For
            End If
        Next
        Session(Constant.SS_SHOPPING_LIST) = oCollection
        Dim strJSClosePage As String = "<script type=""text/javascript"">windowCloseAndRefresh('1');</script>"
        RegisterClientScriptBlock("closePage", strJSClosePage)
    End Sub

End Class
